package gui.tools;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;

/**
 * Setting the Toolbar for the program
 * 
 * @author: Patrik Bakke
 * @version: %I%, %G%
 */
public class ToolBar extends JToolBar {

	private ActionHandler ac;
	private static final long serialVersionUID = 1L;

	/**
	 * Constructor setting the layout and components of the Toolbar
	 * 
	 * @param ac
	 *            The Action Handler for the Toolbar/Program
	 */

	public ToolBar(ActionHandler ac) {
		setLayout(new BorderLayout());
		setOrientation(VERTICAL);
		setFloatable(false);

		JPanel controls = new JPanel(new BorderLayout());
		JPanel zoom = new JPanel (new GridLayout (1,2));
		zoom.add(makeButton("Zoom In", new ImageIcon(
				"src/images/zoomin.png"), ac));
		zoom.add(makeButton("Zoom Out", new ImageIcon(
				"src/images/zoomout.png"), ac));
		JPanel rotate = new JPanel (new GridLayout (2,2));
		rotate.add(makeButton("Rotate CCW", new ImageIcon(
				"src/images/rotateccw.png"), ac));
		rotate.add(makeButton("Rotate CW", new ImageIcon(
				"src/images/rotatecw.png"), ac));
		rotate.add(makeButton("Rotate Up", new ImageIcon(
				"src/images/rotateup.png"), ac));
		rotate.add(makeButton("Rotate Down", new ImageIcon(
				"src/images/rotatedown.png"), ac));
		JPanel pan = new JPanel (new GridLayout(3,3));
		pan.add(new JPanel());
		pan.add(makeButton("Up", new ImageIcon("src/images/up.png"), ac));
		pan.add(new JPanel());
		pan.add(makeButton("Left", new ImageIcon("src/images/left.png"), ac));
		pan.add(makeButton("Reset", new ImageIcon("src/images/reset.png"),
				ac));
		pan.add(makeButton("Right", new ImageIcon("src/images/right.png"), ac));
		pan.add(new JPanel());
		pan.add(makeButton("Down", new ImageIcon("src/images/down.png"), ac));
		pan.add(new JPanel());
		controls.add(zoom, BorderLayout.NORTH);
		controls.add(rotate, BorderLayout.CENTER);
		controls.add(pan, BorderLayout.SOUTH);


		add(controls, BorderLayout.NORTH);
	}

	/**
	 * Setting buttons to be used on the Toolbar.
	 * 
	 * @param name
	 *            Name of the icon/function.
	 * @param icon
	 *            Icon to be displayed on the button.
	 * @return Returns the JButton created.
	 */

	public JButton makeButton(String name, ImageIcon icon, ActionHandler ac) {
		JButton button = new JButton(name, icon);
		button.setVerticalTextPosition(SwingConstants.BOTTOM);
		button.setVerticalTextPosition(SwingConstants.CENTER);
		button.setBorder(null);
		button.addActionListener(ac);
		return button;
	}

}
